package dRegAut.opg3;

/**
 * An automaton state.
 */
public class State implements Cloneable {

    /**
     * State name. (The state name is only for printing and has no formal meaning.)
     */
    public String name;

    /**
     * Constructs a new state with no name.
     */
    public State() {
        name = "";
    }

    /**
     * Constructs a new state with the given name.
     * @param name state name
     */
    public State(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof State) {
            if (name == null || name.equals("")) {
                return super.equals(obj);
            }
            return name.equals(((State)obj).name);
        }

        return false;
    }

    @Override
    public int hashCode() {
        if (name == null || name.equals("")) {
            return super.hashCode();
        }
        return name.hashCode();
    }
    /*
    */

    /**
     * Clones this state object.
     */
    @Override
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String toString() {
        return name;
    }
}
